package com.eastseeway.radioproject.database;

import androidx.room.TypeConverter;

import com.eastseeway.radioproject.entities.OperationParams;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

public class OperationParamsTypeConverter {

    Gson mGson = new Gson();

    @TypeConverter
    public List<OperationParams> stringToObjectList(String data) {
        if (data == null) {
            return Collections.emptyList();
        }

        Type listType = new TypeToken<List<OperationParams>>() {}.getType();

        return mGson.fromJson(data, listType);
    }

    @TypeConverter
    public String objectListToString(List<OperationParams> someObjects) {
        return mGson.toJson(someObjects);
    }

}
